(function () {
    // 点击发布的圈子出来的框
    let seletcircle = document.querySelector(".article-panel>.selet-circle");
    let cirticle = document.querySelector(".article-panel>.circle");
    let cirticlebtn = document.querySelector('.circle-button.content');

    cirticle.addEventListener("click", cirticleFn);
    function cirticleFn() {
        seletcircle.style.marginTop = 0 + "px";
        seletcircle.style.display = "block";
        cirticlebtn.style.top = 330 + 'px';
    }

    // 点击选择框里面的内容后隐藏
    let inputcircle = document.querySelector(".article-panel .circle .input>input");
    let cid = '';
    let tags = document.querySelector('input[type="hidden"]').value;
    seletcircle.onclick = function (event) {
        if (event.target.className === "clickli" || event.target.className === "big") {
            cid = event.target.dataset.cid;
            inputcircle.value = event.target.innerHTML
            tags = event.target.innerHTML
            console.log(cid, tags);
            seletcircle.style.marginTop = 0 + "px";
            seletcircle.style.display = "none";
            inputcircle.style.display = "block";
            cirticlebtn.style.top = 260 + 'px';
        }

    }

    // 用户信息
    axios.get('/api/getAuser1')
        .then(res => {
            // console.log(res)
            if (res.data.code === 1) {
                document.getElementsByClassName('nkname')[0].innerHTML = res.data.userinfo.username;
            }
        })
        .catch(err => {
            console.error(err);
        })


    // 获取当前时间
    // 时间戳格式化
    function formatDate(datetime) {
        var date = new Date(datetime)// 时间戳为10位需*1000，时间戳为13位的话不需乘1000
        var year = date.getFullYear()
        var month = ('0' + (date.getMonth() + 1)).slice(-2)
        var sdate = ('0' + date.getDate()).slice(-2)
        var hour = ('0' + date.getHours()).slice(-2)
        var minute = ('0' + date.getMinutes()).slice(-2)
        var second = ('0' + date.getSeconds()).slice(-2)
        // 拼接
        var result = year + '-' + month + '-' + sdate + ' ' + hour + ':' + minute + ':' + second
        // 返回
        return result;
    }
    // 做判断
    let popupboxdiv = document.querySelector(".popup-box");
    let boxone = document.querySelector(".popup-box>.box-one");


    let issuebtn = document.querySelector(".circle-button>.issue-button");
    issuebtn.onclick = function () {
        console.log(111);
        let title = document.querySelector(".input-title").value;
        let inputcircle = document.querySelector(".article-panel .circle .input>input").value;
        if (!title) {
            popupboxdiv.style.marginTop = 400 + 'px';
            boxone.innerText = "标题内容不能为空";
            popupboxdiv.style.opacity = 1;
            setTimeout(() => {
                popupboxdiv.style.opacity = 0;
            }, 3000);
            return;
        } else if (!inputcircle) {
            popupboxdiv.style.marginTop = 400 + 'px';
            boxone.innerText = "没有选择发的圈子";
            popupboxdiv.style.opacity = 1;
            setTimeout(() => {
                popupboxdiv.style.opacity = 0;
                popupboxdiv.style.marginTop = (-400) + 'px';
            }, 3000);
            return;
        }

        // 获取传递过来的路径信息
        let xx = location.search.split('?')[1].split('&');
        let uid = xx[0].split('=')[1];

        axios.post('/api/publish', {
            title,
            tags,
            cid,
            content: html,
            uid
        }).then(function (res) {
            console.log(res);
            // window.location.href = './index.html';
        }).catch(function (error) {
            console.log(error);
        });
    }
})();